<?php /* Smarty version Smarty-3.0.8, created on 2014-11-03 19:12:44
         compiled from "tpl/js/controller/setting-team-content.js" */ ?>
<?php /*%%SmartyHeaderCode:278055457632c59ad76-48988795%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    '9acb84ab61df71b062b16e44bab3982cd6904fd5' => 
    array (
      0 => 'tpl/js/controller/setting-team-content.js',
      1 => 1410832046,
      2 => 'file',
    ),
  ),
  'nocache_hash' => '278055457632c59ad76-48988795',
  'function' => 
  array (
  ),
  'has_nocache_code' => false,
)); /*/%%SmartyHeaderCode%%*/?>
      //添加删除成员
      App.controller('setting-team-content', function (page,contact) {
        var tpl_str = "\
          <tr class='tr_line' >\
            <td><<?php ?>%=studentid%<?php ?>></td>\
            <td class='username'><<?php ?>%=username%<?php ?>></td>\
            <td><a href='javascript:vide(0)' class='btn btn-default btn-delete' role='button' user_name='<<?php ?>%=username%<?php ?>>' user_id='<<?php ?>%=user_id%<?php ?>>'>删除</a></td>\
          </tr>\
        ";
        var tpl_fun = parseTpl(tpl_str);
        var delete_fun = function(v_this){
            App.dialog({
              title: '您确定要删除成员 '+v_this.attr("user_name")+' 吗？',okButton: '确定',cancelButton: '取消',
            }, function (ok,cancel) {
              if (ok) {
                var this_tr = v_this.parents("tr");
                var user_id = v_this.attr("user_id");
                $.post(url("team","delete_member"),{user_id:user_id},function(data){
                  this_tr.remove();
                  alert("删除成功！");
                },"json");
              }
            });
            return false;
        };
        $(page).on("appReady",function(){
          $(page).find("#team-info").html("名称："+contact.team_name+"<br/>添加时间："+contact.add_time+"&nbsp;&nbsp;&nbsp;&nbsp;管理员："+contact.leader_name);

          $.post(url("team","team_member"),{team_id:contact.team_id},function(data){
            for(var i=0;i<data.length;i++){
              var tr_line = tpl_fun(data[i]);
              $(page).find("#table-hover").append(tr_line); 
            }
           $(page).find("a.btn-delete").on("tap",function(){delete_fun($(this));} );
          },"json");
        });
        
        $(page).find("#ptime-submit-button").on("tap",function(){
          var v_this = $(this);
          var studentids = $("#studentids").val();     
          $.post(url("team","add_member"),{studentids:studentids,team_id:contact.team_id},function(data){
            if(typeof(data.errmsg) != "undefined"){
              alert(data.errmsg);
            }else{
              var alert_str = "";
              if(typeof(data.success) != "undefined"){
                for(var i=0;i<data.success.length;i++){

                  var tr_line = tpl_fun(data.success[i]);
                  $(page).find("#table-hover").append(tr_line);
                }
                $(page).find("a.btn-delete").on("tap",function(){delete_fun($(this));} );
                alert_str += "成功添加"+data.success.length+"个成员！";
              }
              if(typeof(data.none) != "undefined"){
                alert_str += "未注册用户"+data.none.length+"人！";
              }
              if(typeof(data.exist) != "undefined"){
                alert_str += "已存在用户"+data.exist.length+"人！";
              }
              alert(alert_str);
            }


          },"json");     
        });
      });